#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+5;
int n,C,a[N],f[N/10+5][105],sum[N],ans; 
signed main() {
	freopen("minimize.in","r",stdin);
	freopen("minimize.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>C;
	for(int i=1;i<=n;i++) cin>>a[i],sum[i]=sum[i-1]+a[i]; 
	if(!C) cout<<0,exit(0);
	if(C<=100){
		memset(f,0x3f,sizeof(f));
		for(int i=0;i<=101;i++) f[0][i]=0;
		for(int i=1;i<=n;i++){
			for(int j=0;j<=101;j++){
				f[i][j]=f[i-1][j]+(j>=a[i]?j-a[i]:C);
			}
			for(int j=100;j>=0;j--) f[i][j]=min(f[i][j],f[i][j+1]);
		}
		cout<<f[n][0],exit(0);
	}
	ans=C*n;
	for(int i=1;i<=n;i++) ans=min(ans,i*a[i]-sum[i]+(n-i)*C);
	cout<<ans;
	return 0;
}
